#include "Worker.h"
#pragma once

class Node //Two Three Tree node
{
	Node * left;
	Node * middle;
	Node * right;
	Node * parent;
	StringKey min2 , min3;
	StringKey absoluteMin; // hold the absolut min value of the node (smallestMin value of the node)

	// for leaf - will hold the leaf value
	StringKey valueKey;
	
public:
	Worker* value;
	Node();
	Node(Worker* value , StringKey key);
	Node* Find(StringKey key ) ;
	Node* Delete(StringKey key, Worker* &worker) ;
	Node* Insert(Node * node);
	void FreeAllElements();		
	void printNode(int level, char side);
	void printByOrder(ofstream & file);
	bool IsLeaf();
private:
	void init();
	StringKey GetMin();
	void FixOrder(); 
	void updateMinimums();
	Node* FindFather(StringKey key);
	bool NoneRecursiveInsert(Node* node);
	Node* SplitInsert(Node* son);
	
	Node* FindDelete(StringKey key, Worker* &worker);
	Node* borrow(Node* son); // give one of your node to another person
	
	bool NonRecursiveDelete(Node* node);
	Node* getRemaningNode();
	int numOfNodes();

	void InsertToBrother(Node * node, Node * sonToSkip);
	Node* getBrother(Node* son);
};


